package com.ds.api.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ds.api.dao.TypeMachineMapper;
import com.ds.api.model.TypeMachine;
@Service
public class Utils {

    @Autowired
    private TypeMachineMapper mapper;

    public  static Map<Integer,String> callTypeMap;

    private static final Logger logger=LoggerFactory.getLogger(Utils.class);

    @Autowired
    private TypeMachineMapper machine;

    public static   List<Map<String,Object>> childlist=new ArrayList<Map<String,Object>>();;
    @PostConstruct
    public void initCache() {
        logger.info("Dictionary data initialization");
        List<TypeMachine> list=machine.query(new HashMap<String, Object>());
        callTypeMap=new HashMap<Integer, String>();
        for(TypeMachine l:list){
            callTypeMap.put(l.getUid(), l.getName());
        }
        logger.info("Dictionary data list1 size is :{}",list.size());

        Map<String, Object> childrenMap = null;

        Map<String,Object> param=new HashMap<String,Object>();
        Map<String,Object> param2=new HashMap<String,Object>();

        param.put("fkParentId", 39);
        List<Map<String,Object>> lists=mapper.queryTree(param);
        for (Map<String,Object> model : lists) {

            childrenMap = new  LinkedHashMap<String, Object>();

            param2.put("fkParentId", model.get("value"));
            List<Map<String,Object>> list1=mapper.queryTree(param2);
            if(list1.size()>0){
                model.put("children", list1);
                for (Map<String, Object> map : list1) {
                    param2.clear();
                    param2.put("fkParentId", map.get("value"));
                    List<Map<String,Object>>  list3=mapper.queryTree(param2);
                    map.put("children", list3);
                }
            }
            childlist.add(model);
        }
    }
}  